var participate_botton=document.getElementById("participate_botton");
var friend_jz=document.getElementsByClassName("friend_jz")[0];
var cover=document.getElementsByClassName("cover")[0];
friend_jz.onclick=function(){
	cover.style.display = "block";
	cover.onclick=function(){
		cover.style.display = "none";
	}
}

var Request = new Object(); 
Request = GetRequest();

//全局变量 
var mppId,activeId;
ajax({
	url:"http://www.antmall.cc/public/wx/collect/data/"+activeId+"/"+mppId+".html",
	success:function(data){
		var info = JSON.parse(data);
		var gift=info.data.gift;
		var giftReceive=info.data.giftReceive;
		var oImg=document.getElementsByClassName("left")[0];
		var title=document.getElementsByClassName("title")[0];
		var total_num=document.getElementsByClassName("totalNum")[0];
		var address=document.getElementsByClassName("address")[0];
		var price_num=document.getElementsByClassName("price_num")[0];

		oImg.style.backgroundImage = "url("+gift.giftImg+")";
		title.innerHTML=giftReceive.title;
		total_num.innerHTML=giftReceive.giftTotal;
		address.innerHTML=info.data.active.bizShop.address;
		price_num.innerHTML=(giftReceive.giftPrice)/100;
		

		var xs_center=document.getElementsByClassName("xs_center")[0];
		xs_center.innerHTML=gift.samples;


		var num=giftReceive.giftTotal;
		var join_num=giftReceive.likedTotal;

		function star(num,join_num){
		    var jd_bg=document.getElementById("jd_bg");
		    var jd_bg_num=document.getElementById("jd_bg_num");
		    var already=jd_bg_num.getElementsByTagName("i")[0];
			var less=jd_bg_num.getElementsByTagName("strong")[0];
			var friend_num=document.getElementById("friend_num");
		    jd_bg.style.width=100*(join_num/num)+"%";
		    already.innerHTML=join_num;
		    less.innerHTML=num-join_num;
		    ajax({
				url:"http://www.antmall.cc/public/wx/collect/data/voteAvatar.html"+"?"+"mppId="+mppId,
				success:function(data){
					var info = JSON.parse(data);
					for(var j=0;j<join_num;j++){
			    	if(join_num){
						num=document.createElement("div");
				    	num.className="num";
				    	friend_num.appendChild(num);
				    	num.style.backgroundImage = "url("+info.data[j].headImgUrl+")"
			    	}	
    		}
				}
			})
		    
		}
		star(num,join_num);

		if(num==join_num){
			participate_botton.onclick=function(){
			    window.location.href="dhjp.html";
			}
		}else {
			var prompt_cover=document.getElementsByClassName("prompt_cover")[0];
			participate_botton.onclick=function(){
			    prompt_cover.style.display = "block";
			    setTimeout(
						function(){
							prompt_cover.style.display = "none";
					},1000)
				prompt_cover.onclick=function(){
					prompt_cover.style.display = "none";
				}

			}
		}

	}
})



function ajax(info){
	if(window.XMLHttpRequest){
		var xhr = new XMLHttpRequest();	
	}else{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url = info.url;
	var type = info.type||"GET";
	var data = info.data||"";
	
	if(type=="GET"){
		xhr.open("GET",url+data+"&t="+new Date().getTime(),true);
		xhr.send();
	}else{
		xhr.open("POST",url,true);
		xhr.setRequestHeader("myHeader","myvalue");
		xhr.send(data);
	}
	
	xhr.onload = function(){
		if(info.success){
			info.success(xhr.responseText);
		}
	}
}
